package nl.fonfolio.view {
	import flash.display.Sprite;

	import nl.fonfolio.core.FonfolioEvent;
	import nl.fonfolio.model.Model;
	import nl.fonfolio.controller.Controller;
	import nl.fonfolio.view.avatar.Avatar;
	import nl.fonfolio.core.Fonfolio;	
	
	/**
	 * @author User
	 */
	public class Level extends Sprite {
		private var fonfolio : Fonfolio;
		private var model : Model;
		private var controller : Controller;

		public function Level(fonfolio : Fonfolio,model : Model,controller : Controller) {
			this.controller = controller;
			this.model = model;
			this.fonfolio = fonfolio;
			
			this.model.addEventListener(FonfolioEvent.CONTROL_TYPE, onLoadLevel);
		}

		public function onLoadLevel(event : FonfolioEvent) : void {
			trace("LEVEL: Loaded");
			if (event.command == "LOAD_LEVEL"){
			var level : Object = this.model.getLevel();

			for (var i : Number = 0;i < level.student.length; i++) {
				var student:Object = level.student[i];
				var avatar:Avatar = new Avatar(this.fonfolio, this.model, this.controller, student);
				avatar.x = i * 100 + 50;
				
				avatar.y = 50;
				this.addChild(avatar);
			}
			}
		}
	}
}
